class Solution {
    public List<List<Integer>> levelOrderBottom(TreeNode root) {
       List<List<Integer>> list = new ArrayList<>();
        if(root == null) return list ;
        Stack<List<Integer>> stack = new Stack<>() ;
        Queue<TreeNode> queu = new LinkedList<>() ;
        queu.offer(root);
        while(!queu.isEmpty()){
            int size = queu.size() ;
             List<Integer> ret = new ArrayList<>() ;
            while(size > 0){
                TreeNode cur = queu.poll() ;
                ret.add(cur.val);
                if(cur.left != null){
                    queu.offer(cur.left);
                }
                if(cur.right != null){
                    queu.offer(cur.right);
                }
                size-- ;
            }
            stack.push(ret);
        }
        while(!stack.empty()){
            list.add(stack.peek());
            stack.pop() ;
        }
        return list ;

    }
}